<?php
namespace App\Http\Controllers\Business\App\OrderManagement;

use App\Models\Shop;
use App\Models\Order;
use App\Models\User;

class OrderManagement
{
    //商家二维码
    public static function getOrderByOrderNumber($orderNumber) {
        if(!$orderNumber) {
            return ['status'=>'failed', 'message'=>'请输入订单号'];
        }
        //是不是地推商家
        $data = Order::where('orders.ordernumber', $orderNumber)
            ->join('users', 'orders.userid', '=', 'users.id')
            ->select('users.nickname', 'users.mobile','orders.ordernumber','orders.shopname','orders.orderamount','orders.actualamount','orders.redenvelopeamount','orders.fee','orders.created_at')
            ->first();
        if(!$data) {
            return ['status'=>'failed', 'message'=>'找不到订单'];
        }
        $nickName = $data['nickname'];
        if(is_numeric($nickName) && (strlen($nickName) == 11)) {
            $data['nickname'] = str_replace(substr($data['nickname'],3,4),'****',$data['nickname']);
        }
        $data['mobile'] = str_replace(substr($data['mobile'],3,4),'****',$data['mobile']);
        return ['status'=>'success', 'data'=>$data];
    }
}